package cn.hotel.dao;

import cn.hotel.pojo.Administrator;
import cn.hotel.utlis.Crud;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class LogInDao extends Crud implements LogIns {
    @Override
    public Administrator logIn(String name, String password) {
        String sql = "SELECT * from administrator where administratorNumber = ? AND password = ?";
        List<Object> data = new ArrayList<>();
        data.add(name);
        data.add(password);
        ResultSet resultSet = getResultSet(sql,data);
        Administrator administrator = null;

        try {
            while (resultSet.next()){
                administrator = new Administrator();
                administrator.setAdministratorNumber(resultSet.getString(2));
                administrator.setPassword(resultSet.getString(3));
                administrator.setMemberJurisdiction(resultSet.getInt(4));
                administrator.setDoBusinessJurisdiction(resultSet.getInt(5));
                administrator.setGoodsJurisdiction(resultSet.getInt(6));
                administrator.setManageJurisdiction(resultSet.getInt(7));
                administrator.setLogJurisdiction(resultSet.getInt(8));
                administrator.setFinanceJurisdiction(resultSet.getInt(9));
            }
            return administrator;
        } catch (Exception exception) {
            exception.printStackTrace();
        } finally {
            this.setClear(resultSet);
        }
        return administrator;
    }
}
